package ODtest.tongjicj;

import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            int n = in.nextInt(); // N次比赛
            String ids = in.nextLine();  // ids
            String cjd = in.nextLine(); // 成绩单
            String[] idsObj = ids.split(",");
            String[] cjdObj = cjd.split(",");
            Map<String,Integer> idCountMap = new HashMap<>();
            Map<String,Integer> cjdCountMap = new HashMap<>();
            for (int i = 0; i < idsObj.length; i++) {
                String id = idsObj[i];
                if (idCountMap.containsKey(id)) {
                    idCountMap.put(id, count.get(id) + 1);
                } else {
                    idCountMap.put(id, 1);
                }

                Integer cj = Integer.getInteger(cjdObj[i]);
                if (cjdCountMap.containsKey(cj)) {
                    cjdCountMap.put(id, count.get(id) + cj);
                } else {
                    cjdCountMap.put(id, 1);
                }
            }

            // 输出
            cjdCountMap.entrySet().parallelStream().sorted().forEach(e-> {
                System.out.println(e.getKey());
                System.out.println(",");
            });
        }
    }
}